<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'deletepro.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
	<script>
			function showLabel(pid){
				$("#"+pid).toggle();
				$.getJSON("getLabelByProductIdAction",{"productId":pid},function(data){
						if(data.labels.length>0){
		    				$("#"+pid).html("");
		    				$.each(data.labels,function(index,value){
		    					$("#"+pid).append("<div id='child"+value.labelId+"'></div>");
				    			$("#child"+value.labelId+"").append(value.labelName);
				    			$("#child"+value.labelId+"").append("<a href='javascript:void(0);' onclick='deleteLabel("+value.labelId+")'><img style='padding-left: 5px;' width='10px' height='10px' src='img/d2.gif'></a>");
				 			});
		    			}else{
		    				$("#"+pid).html("该产品还没有款式");
		    			}
				});	     		
			}
			function deleteLabel(lid){
					if(window.confirm("确定要删除")){
						$.post("DeleteLabelByLidAction",{"labelId":lid},function(data){
								if(data=="success"){
									$("#child"+lid).html("");
									alert("删除成功");
								}else if(data=="fail"){
									$("#child"+lid).html("");
									alert("删除失败");
								}
							
						});
					
					}else{}
			}
	function deleteProduct(pid){
		if(window.confirm("确定要删除该产品")){
			$.post("DeleteProductByPidAction",{"productId":pid},function(data){
								if(data=="success"){
									$("#p"+pid).html("");
									alert("删除成功");
								}else{
									$("#p"+pid).html("");
									alert("删除失败");
								}
				});
		}else{}
	}
	</script>
  </head>
  
  <body>
    		<div align="center"><h2>删除产品</h2></div>
			<div style="width: 300px; height: 1300px; margin-left: 500px;">
					<c:forEach items="${product}" var="pro">
							<div id="p${pro.productId}">
								<ul>
									<li><a href="javascript:void(0);" onclick="showLabel(${pro.productId})">${pro.productName}</a><a href="javascript:void(0);" onclick="deleteProduct(${pro.productId})"><img style="padding-left: 5px;" width="10px" height="10px" src="img/d1.gif"></a></li>
									<div id="${pro.productId}" style="display: none; padding-left: 8px;"></div>
								</ul>
							</div>
					</c:forEach>
			  
       	    </div>
  </body>
</html>
